Copyright>        OpenRadioss
Copyright>        Copyright (C) 1986-2023 Altair Engineering Inc.
Copyright>
Copyright>        This program is free software: you can redistribute it and/or modify
Copyright>        it under the terms of the GNU Affero General Public License as published by
Copyright>        the Free Software Foundation, either version 3 of the License, or
Copyright>        (at your option) any later version.
Copyright>
Copyright>        This program is distributed in the hope that it will be useful,
Copyright>        but WITHOUT ANY WARRANTY; without even the implied warranty of
Copyright>        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Copyright>        GNU Affero General Public License for more details.
Copyright>
Copyright>        You should have received a copy of the GNU Affero General Public License
Copyright>        along with this program.  If not, see <https://www.gnu.org/licenses/>.
Copyright>
Copyright>
Copyright>        Commercial Alternative: Altair Radioss Software
Copyright>
Copyright>        As an alternative to this open-source version, Altair also offers Altair Radioss
Copyright>        software under a commercial license.  Contact Altair to discuss further if the
Copyright>        commercial version may interest you: https://www.altair.com/radioss/.
Chd|====================================================================
Chd|  R2R_INPUT                     source/coupling/rad2rad/r2r_input.F
Chd|-- called by -----------
Chd|        R2R_GROUP                     source/coupling/rad2rad/r2r_group.F
Chd|-- calls ---------------
Chd|        INOUTFILE_MOD                 ../common_source/modules/inoutfile_mod.F
Chd|        R2R_MOD                       share/modules1/r2r_mod.F      
Chd|        RESTMOD                       share/modules1/restart_mod.F  
Chd|====================================================================
      SUBROUTINE R2R_INPUT(IEXTER)
C-----------------------------------------------
C   M o d u l e s
C-----------------------------------------------
      USE RESTMOD
      USE R2R_MOD
      USE INOUTFILE_MOD
C-----------------------------------------------
C   I m p l i c i t   T y p e s
C-----------------------------------------------
#include      "implicit_f.inc"
C-----------------------------------------------
C   C o m m o n   B l o c k s
C-----------------------------------------------
#include      "com01_c.inc"
#include      "com04_c.inc"
#include      "scr17_c.inc"
#include      "param_c.inc"
#include      "r2r_c.inc"
C-----------------------------------------------
C   D u m m y   A r g u m e n t s
C-----------------------------------------------
      INTEGER IEXTER(NR2R,*)   
C-----------------------------------------------
C   L o c a l   V a r i a b l e s
C-----------------------------------------------
      INTEGER REF,I,J,S,START,ADDRESS(NSUBDOM+1),NB(NSUBDOM+1)
      INTEGER COMPT,TAB_TMP((NSUBDOM+1)*NR2RLNK),IDOM,TLK
      CHARACTER NAME_FULL*150,NAM*150,NAM_TMP*150,LINKZ*80,CHRUN*4    
      INTEGER :: LEN_TMP_NAME
      CHARACTER(len=4096) :: TMP_NAME
C-----------------------------------------------     

      REF = 1981
      TAB_TMP(:)=0

C-----Creation of arrays for Links---

      COMPT = 1
 
      DO I=0,NSUBDOM
      	ADDRESS(I+1)=COMPT
       	START = NSLASH(KR2R)+1     
      	DO J=START,NR2RLNK
          IF ((IEXTER(3,J)==I).OR.(IEXTER(4,J)==I)) THEN
	    TAB_TMP(COMPT)=IEXTER(2,J)
	    COMPT = COMPT+1	   
	  ENDIF
      	END DO

      	NB(I+1)=COMPT-ADDRESS(I+1)
      END DO

C-------------------------------------

      WRITE(CHRUN,'(I4.4)')IRUN
      ! *r2r is an input file for the engine
      NAM = ROOTNAM0(1:LEN_TRIM(ROOTNAM0))//'_'//CHRUN//'.r2r'
      TMP_NAME=INFILE_NAME(1:INFILE_NAME_LEN)//NAM(1:LEN_TRIM(NAM))
      LEN_TMP_NAME = INFILE_NAME_LEN+LEN_TRIM(NAM)

      OPEN(UNIT=REF,FILE=TMP_NAME(1:LEN_TMP_NAME),
     .      ACCESS='SEQUENTIAL',FORM='FORMATTED',STATUS='UNKNOWN')
   
      WRITE(REF,1000)'--------------------------------------------'  
      WRITE(REF,1000)' RAD2RAD INPUT FILE - GENERATED BY STARTER  ' 
      WRITE(REF,1000)'--------------------------------------------' 
      WRITE(REF,1400)'$         '
                               
C-----Generation of domains input cards--------

      WRITE(REF,1000)'--------------------------------------------' 
      WRITE(REF,1000)' 1. DOMAINS                                 ' 
      WRITE(REF,1000)'--------------------------------------------'
      NAME_FULL=ROOTNAM0(1:LEN_TRIM(ROOTNAM0))
      WRITE(REF,1100) NAME_FULL
      
      DO I=1,NSUBDOM+1
        IF ((I-1)/=0) THEN
	 NAM=DOM_NAME(ISUBDOM(8,I-1):ISUBDOM(8,I-1)+ISUBDOM(7,I-1)-1)
	 WRITE(REF,1100) NAM
	ENDIF   
	WRITE(REF,1500) (TAB_TMP(J+ADDRESS(I)-1),J=1,NB(I))
      END DO
         
C-----Generation of interfaces input cards -----

      WRITE(REF,1000)'--------------------------------------------'  
      WRITE(REF,1000)' 2. INTERFACES                              ' 
      WRITE(REF,1000)'--------------------------------------------' 
       
      DO I=START,NR2RLNK          
        IF (IEXTER(5,I)==40) THEN
C--->  type = 40 -> interface for main nodes of RBODY -----	 
          WRITE(REF,1310) IEXTER(5,I)/10
        ELSEIF (IEXTER(5,I)==50) THEN
C--->  type = 50 -> interface type KINE----------------- -----	 
          WRITE(REF,1330) IEXTER(5,I)/10
        ELSEIF (IEXTER(5,I)==60) THEN
C--->  type = 60 -> interface type FSI------------------ -----
          TLK = 4	 
          IF (FLG_TIED(5)==1) THEN
            WRITE(REF,1350) TLK
          ELSE
            WRITE(REF,1340) TLK
          ENDIF
          WRITE(REF,*) ' 0.1'
        ELSEIF (IEXTER(5,I)==70) THEN
C--->  type = 70 -> interface type NLOCAL--------------- -----
          TLK = 4	 
          WRITE(REF,1360) TLK        
	ELSEIF (FLG_TIED(IEXTER(5,I))==1) THEN
	  WRITE(REF,1320) IEXTER(5,I)           
	ELSE
          WRITE(REF,1300) IEXTER(5,I)	
	ENDIF
	WRITE(LINKZ,1800) IEXTER(2,I)		
C--------
        DO J=1,2
	  IF (IEXTER(2+J,I)==0) THEN
	      NAM_TMP = NAME_FULL
	  ELSE	        
	      IDOM = IEXTER(2+J,I)
	      S = ISUBDOM(8,IDOM)	       
	      NAM_TMP = DOM_NAME(S:S+ISUBDOM(7,IDOM)-1)
	  ENDIF     		
	  NAM=TRIM(NAM_TMP)//'  '//TRIM(LINKZ)	 	   
          WRITE(REF,1900) NAM	 
        END DO
C--------	
      END DO
  
C-----Generation of options input cards--------
			       
      WRITE(REF,1000)'--------------------------------------------'  
      WRITE(REF,1000)' 3. OPTIONS                                 ' 
      WRITE(REF,1000)'--------------------------------------------'

      WRITE(REF,1400)'/SIFF     '       
      WRITE(REF,1400)'/MLTPS/ON ' 
      WRITE(REF,1400)'$         '
      WRITE(REF,1400)'/END      '	
      CLOSE(REF)
      	   			              
C--------------------------------------------------------------C
      RETURN
   
 1000 FORMAT('$',A44)       
 1100 FORMAT('/DOMAIN/',A100)     
 1300 FORMAT('/LINK/TYPE',I1)
 1310 FORMAT('/LINK/TYPE',I1,'/RBODY')
 1320 FORMAT('/LINK/TYPE',I1,'/TIED')
 1330 FORMAT('/LINK/TYPE',I1,'/KINE')
 1340 FORMAT('/LINK/TYPE',I1,'/FSI')
 1350 FORMAT('/LINK/TYPE',I1,'/TIED/FSI')
 1360 FORMAT('/LINK/TYPE',I1,'/NLOCAL')
 1400 FORMAT('',A10)
 1500 FORMAT(  3X,10I5)
 1600 FORMAT('   ',A10,I10)
 1700 FORMAT('   SUBDOMAIN',I1,I10)
 1800 FORMAT(I10)
 1900 FORMAT('   ',A100)                      
C-----------
  
      RETURN
      END                             
